home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / beveled-button.scm < prev    next >
Encoding:
Text File  |  2009-08-19  |  5.6 KB  |  161 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; Button00 --- create a simple beveled Web button
  5. ; Copyright (C) 1997 Federico Mena Quintero
  6. ; federico@nuclecu.unam.mx
  7. ;
  8. ; This program is free software: you can redistribute it and/or modify
  9. ; it under the terms of the GNU General Public License as published by
  10. ; the Free Software Foundation; either version 3 of the License, or
  11. ; (at your option) any later version.
  12. ;
  13. ; This program is distributed in the hope that it will be useful,
  14. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ; GNU General Public License for more details.
  17. ;
  18. ; You should have received a copy of the GNU General Public License
  19. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20. ; ************************************************************************
  21. ; Changed on Feb 4, 1999 by Piet van Oostrum <piet@cs.uu.nl>
  22. ; For use with GIMP 1.1.
  23. ; All calls to gimp-text-* have been converted to use the *-fontname form.
  24. ; The corresponding parameters have been replaced by an SF-FONT parameter.
  25. ; ************************************************************************
  26.  
  27.  
  28. (define (text-width extents)
  29.   (car extents))
  30.  
  31. (define (text-height extents)
  32.   (cadr extents))
  33.  
  34. (define (text-ascent extents)
  35.   (caddr extents))
  36.  
  37. (define (text-descent extents)
  38.   (cadr (cddr extents)))
  39.  
  40. (define (blend-bumpmap img
  41.                        drawable
  42.                        x1
  43.                        y1
  44.                        x2
  45.                        y2)
  46.   (gimp-edit-blend drawable FG-BG-RGB-MODE DARKEN-ONLY-MODE
  47.                    GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE
  48.                    FALSE 0 0 TRUE
  49.                    x1 y1 x2 y2))
  50.  
  51. (define (script-fu-button00 text
  52.                             size
  53.                             font
  54.                             ul-color
  55.                             lr-color
  56.                             text-color
  57.                             padding
  58.                             bevel-width
  59.                             pressed)
  60.   (let* (
  61.         (text-extents (gimp-text-get-extents-fontname text
  62.                                                       size
  63.                                                       PIXELS
  64.                                                       font))
  65.         (ascent (text-ascent text-extents))
  66.         (descent (text-descent text-extents))
  67.  
  68.         (img-width (+ (* 2 (+ padding bevel-width))
  69.                       (text-width text-extents)))
  70.         (img-height (+ (* 2 (+ padding bevel-width))
  71.                        (+ ascent descent)))
  72.  
  73.         (img (car (gimp-image-new img-width img-height RGB)))
  74.  
  75.         (bumpmap (car (gimp-layer-new img
  76.                                       img-width img-height RGBA-IMAGE
  77.                                       "Bumpmap" 100 NORMAL-MODE)))
  78.         (gradient (car (gimp-layer-new img
  79.                                        img-width img-height RGBA-IMAGE
  80.                                        "Gradient" 100 NORMAL-MODE)))
  81.         )
  82.  
  83.     (gimp-context-push)
  84.  
  85.     (gimp-image-undo-disable img)
  86.  
  87.     ; Create bumpmap layer
  88.  
  89.     (gimp-image-add-layer img bumpmap -1)
  90.     (gimp-context-set-foreground '(0 0 0))
  91.     (gimp-context-set-background '(255 255 255))
  92.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  93.  
  94.     (gimp-rect-select img 0 0 bevel-width img-height CHANNEL-OP-REPLACE FALSE 0)
  95.     (blend-bumpmap img bumpmap 0 0 (- bevel-width 1) 0)
  96.  
  97.     (gimp-rect-select img 0 0 img-width bevel-width CHANNEL-OP-REPLACE FALSE 0)
  98.     (blend-bumpmap img bumpmap 0 0 0 (- bevel-width 1))
  99.  
  100.     (gimp-rect-select img (- img-width bevel-width) 0 bevel-width img-height CHANNEL-OP-REPLACE FALSE 0)
  101.     (blend-bumpmap img bumpmap (- img-width 1) 0 (- img-width bevel-width) 0)
  102.  
  103.     (gimp-rect-select img 0 (- img-height bevel-width) img-width bevel-width CHANNEL-OP-REPLACE FALSE 0)
  104.     (blend-bumpmap img bumpmap 0 (- img-height 1) 0 (- img-height bevel-width))
  105.  
  106.     (gimp-selection-none img)
  107.  
  108.     ; Create gradient layer
  109.  
  110.     (gimp-image-add-layer img gradient -1)
  111.     (gimp-context-set-foreground ul-color)
  112.     (gimp-context-set-background lr-color)
  113.  
  114.     (gimp-edit-blend gradient FG-BG-RGB-MODE NORMAL-MODE
  115.                      GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE
  116.                      FALSE 0 0 TRUE
  117.                      0 0 (- img-width 1) (- img-height 1))
  118.  
  119.     (plug-in-bump-map RUN-NONINTERACTIVE img gradient bumpmap
  120.                       135 45 bevel-width 0 0 0 0 TRUE pressed 0)
  121.  
  122.     ; Create text layer
  123.  
  124.     (gimp-context-set-foreground text-color)
  125.     (let ((textl (car (gimp-text-fontname
  126.                        img -1 0 0 text 0 TRUE size PIXELS font))))
  127.       (gimp-layer-set-offsets textl
  128.                               (+ bevel-width padding)
  129.                               (+ bevel-width padding descent)))
  130.  
  131.     ; Done
  132.  
  133.     (gimp-selection-none img)
  134.     (gimp-image-undo-enable img)
  135.     (gimp-display-new img)
  136.  
  137.     (gimp-context-pop)
  138.   )
  139. )
  140.  
  141. (script-fu-register "script-fu-button00"
  142.   _"Simple _Beveled Button..."
  143.   _"Create a simple, beveled button graphic for webpages"
  144.   "Federico Mena Quintero"
  145.   "Federico Mena Quintero"
  146.   "June 1997"
  147.   ""
  148.   SF-STRING     _"Text"               "Hello world!"
  149.   SF-ADJUSTMENT _"Font size (pixels)" '(16 2 100 1 1 0 1)
  150.   SF-FONT       _"Font"               "Sans"
  151.   SF-COLOR      _"Upper-left color"   '(0 255 127)
  152.   SF-COLOR      _"Lower-right color"  '(0 127 255)
  153.   SF-COLOR      _"Text color"         "black"
  154.   SF-ADJUSTMENT _"Padding"            '(2 1 100 1 10 0 1)
  155.   SF-ADJUSTMENT _"Bevel width"        '(4 1 100 1 10 0 1)
  156.   SF-TOGGLE     _"Pressed"            FALSE
  157. )
  158.  
  159. (script-fu-menu-register "script-fu-button00"
  160.                          "<Image>/File/Create/Buttons")
  161.